package com.kl.forum.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kl.forum.dao.HealthyNumMapper;
import com.kl.forum.entity.HealthyNum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HealthyNumService {
    @Autowired
    private HealthyNumMapper healthyNumMapper;

    public List<Map> findHealthy(int userId){
        Map map=new HashMap();
        map.put("userId",userId);
       return healthyNumMapper.findHealthy(map);
    }
    public List<Map> findHealthyAll(){
        Map map=new HashMap();
        return healthyNumMapper.findHealthy(map);
    }
    public HealthyNum findHealthyById(int id){
        return healthyNumMapper.selectByPrimaryKey(id);
    }

    public PageInfo findMyHealthyNumByUserId(Integer userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Map map=new HashMap();
        map.put("userId",userId);
        List<Map> list=healthyNumMapper.findHealthy(map);
        PageInfo<Map> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    public int update(HealthyNum healthyNum){
        return  healthyNumMapper.updateByPrimaryKeySelective(healthyNum);
    }



    public PageInfo findHealthyNumByType(Integer type, Integer userId,Integer pageNum ,Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        Map map=new HashMap();
        map.put("userId",userId);
        map.put("type",type);
        List<Map> list=healthyNumMapper.findHealthyNumByTypeStatus(map);
        PageInfo<Map> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


    public PageInfo searchHealthyName(String keyWord, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Map map=new HashMap();
        map.put("keyWord",keyWord);
        List<Map> list=healthyNumMapper.searchHealthyName(map);
        PageInfo<Map> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
